<template>
  <el-dropdown>
    <svg-icon class="svg" icon-class="language" />
    <template #dropdown>
      <el-dropdown-menu>
        <!-- zh -->
        <el-dropdown-item
          :disabled="$i18n.locale === 'zh'"
          @click.native="changeLang('zh')"
        >中文</el-dropdown-item>
        <!-- en -->
        <el-dropdown-item
          :disabled="$i18n.locale === 'en'"
          @click.native="changeLang('en')"
        >en</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script>
import jsCookie from 'js-cookie'
export default {
  name: 'HmLang',
  methods: {
    changeLang(code) {
      this.$i18n.locale = code
      jsCookie.set('lang', code)
      this.$router.go(0)
    }
  }
}
</script>

<style lang="scss" scoped>
.svg {
  font-size: 18px;
  color: #fff;
}
</style>
